package com.example.myproject.kotlin

fun main() {
    val res = makeString(24)
    println(res)

    val price = toPrice("隆江猪脚饭")
    println(price)


    val score = getGrade(59)
    println(score)

    // 测试循环
    // 1-10 循环10次 依次输出 数字
    for (num in 1..10) {
        println(num)
    }
    // 1-10 循环9次 取不到10 依次输出 数字
    for (i in 1 until 10) {
        println(i)
    }
    // 1-10 循环5次 步长为2
    for (i in 1..10 step 2) {
        println(i)
    }
    // 1-10 循环10次 步长为2 倒序
    for (i in 10 downTo 1 step 2) {
        println(i)
    }

    // while循环和 鸿蒙一样
    // while 死循环
    while (true) {
        println("死循环")
    }

    // 一定会执行依次
    do {

    } while (true)

}

fun makeString(age: Int): String {
    if (age < 6) {
        return "玩泥巴"
    } else if (age >= 6 && age < 18) {
        return "学习"
    } else if (age >= 18 && age < 25) {
        return "可以去网吧打游戏"
    } else {
        return "男孩子的晚婚年龄到了"
    }
}

fun toPrice(food: String): Number {
    val price = when (food) {
        "隆江猪脚饭" -> 15
        "猪脚拼烧鸭" -> 18
        "三拼饭" -> 20
        "全家福" -> 25
        else -> 0
    }
    return price
}

// 根据分数 返回评级，用when实现
fun getGrade(score: Int): String {
    return when (score) {
        in 0..59 -> "不及格"
        in 60..69 -> "及格"
        in 70..79 -> "良好"
        in 80 until 90 -> "优秀"
        in 90..100 -> "优秀"
        else -> "输入的分数有误"
    }
}
